package com.etrans.web.gps.business.log.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.etrans.web.gps.business.log.domain.OperateRecord;
import com.etrans.web.gps.business.log.domain.OperateRecordvo;
import com.etrans.web.gps.common.Constant;
import com.etrans.web.gps.common.MGTemplete;
import com.etrans.web.gps.common.page.PageVo;

@Service
public class OperationRecordService {
	
	public void  insertlog(OperateRecord log){
		MGTemplete.insertOne("LogRecord", "OperateRecord",log);
	}
	
	
	public PageVo getRecord(OperateRecordvo vo,Map<String,Object> maps){	
		HashMap<String,Object> map = new HashMap<String,Object>();	
		HashMap<String,Object> whereMap = new HashMap<String,Object>();
		HashMap<String,Object> sortMap = new HashMap<String,Object>();
		int pageNum =(int)maps.get("page");
		int pageSize =(int)maps.get("pageSize");
		whereMap.put("userId", vo.getUserid());
		if(vo.getStartTime()!=null){
			map.put("$gte",vo.getStartTime());
		}
		if(vo.getEndTime()!=null){
			map.put("$lt", vo.getEndTime());
		}
		if(vo.getStartTime()!=null||vo.getEndTime()!=null){
			whereMap.put("operationTime", map);
		}
		if(vo.getModuleName()!=null){
			whereMap.put("moduleName", vo.getModuleName());
		}
		sortMap.put("operationTime",Constant.MONGODB_DESC);	
		List<OperateRecord> list = MGTemplete.find("LogRecord", "OperateRecord",whereMap,sortMap,pageNum,pageSize,OperateRecord.class);
		PageVo pageVo = new PageVo();
		Integer total = null;
			total =MGTemplete.findCount("LogRecord", "OperateRecord",whereMap).intValue();
			pageVo.setTotal(total);
			pageVo.setRows(list);
			pageVo.setPage((Integer) maps.get("page"));
		return pageVo;
	}
	
}
